package cn.sdormitory.homepage.service.impl;

import cn.sdormitory.common.exception.ApiException;
import cn.sdormitory.homepage.dao.HomePageDao;
import cn.sdormitory.homepage.service.HomePageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class HomePageServiceImpl implements HomePageService {

    @Autowired
    HomePageDao homePageDao;

    @Override
    public Map<String, Object> findData() throws ApiException {
        Map<String,Object> map = new HashMap<>();
        //获取今天日期
        Date today = new Date();
        //获取昨天日期
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(today);
//        calendar.add(Calendar.DAY_OF_MONTH,-1);
//        Date yesterday = calendar.getTime();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        String todayStr = fmt.format(today);
        String startedToday = todayStr + " 00:00:00";
        String endedToday = todayStr + " 23:59:59";
//        String yesterdayStr = fmt.format(yesterday);
            //### 一.缺勤情况 ###
        //1.班级缺勤人员名单
        map.put("classAbsence",homePageDao.findClassAbsenceList(todayStr));
        //2.宿舍缺勤人员名单
        map.put("dormitoryAbsence",homePageDao.findDormitoryAbsenceList(startedToday,endedToday));
            //### 二.卫生情况 ###
        //1.班级卫生
        map.put("classHygiene",homePageDao.findClassHygieneList(todayStr));
        //2.宿舍卫生
        map.put("dormitoryHygiene",homePageDao.findDormitoryHygieneList(todayStr));
            //### 三.个人卫生情况 ###
        //1.个人卫生优秀名单
        map.put("excellentPersonalHygiene",homePageDao.findExcellentPersonalHygieneList(todayStr));
        //2.个人卫生查名单
        map.put("poorPersonalHygiene",homePageDao.findPoorPersonalHygieneList(todayStr));
            //### 四.报修情况 ###
        //1.班级报修情况
        map.put("classRepair",homePageDao.findClassRepairList(startedToday,endedToday));
        //2.宿舍报修情况
        map.put("dormitoryRepair",homePageDao.findDormitoryRepairList(startedToday,endedToday));
            //### 五.请假学生 ###
        return map;
    }
}
